/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.*;
import java.util.logging.*;

/**
 *
 * @author Солнце
 */
public class ProcessingPoints {
    public static Points loadData(String fileName) {
        try {
            Points allPoints = new Points();
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
            int n = in.readInt();
            for (int i = 0; i < n; i++) {
                allPoints.addPoint((Point) in.readObject());
            }
            in.close();
            return allPoints;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Flights.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (IOException ex) {
            Logger.getLogger(Flights.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public static void saveData(String fileName, Points allPoints) {
        try {
            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(fileName));
            out.writeInt(allPoints.getSize());
            for (int i = 0; i < allPoints.getSize(); i++) {
                out.writeObject(allPoints.getRouteByIndex(i));
            }
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(Flights.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
